<%@ Master Language="C#" MasterPageFile="~/Views/Shared/Templates/Include/Sublayout.Master"
    Inherits="System.Web.Mvc.ViewMasterPage<FiltronASP.ViewModels.CMS.CMSViewModel>" %>

<%@ Import Namespace="FiltronASP.Helpers.HtmlTags" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <section class="white">

            <div class="container ">
                <div class="row">



                    <div class="col-xs-12" style="  font-size: 30px;
                         font-family: 'Din Medium', sans-serif!important;">
                        <h2>
                            <%= FiltronASP.Helpers.Translations.translationHelper.getTranslationFromTemplate("_newsAllNews", Model.PageToGenerate)%>
                        </h2>
                    </div>
                    
                    <asp:ContentPlaceHolder ID="implementationsAllMonth" runat="server">
                            <%= implementationsAllMonth.GenerateCmsContent(Model.PageToGenerate)%>                
                        </asp:ContentPlaceHolder>   
                      <div class=" col-xs-12 results-ajax filters-resp-padding" style="  background: #fff;" >
                            <div class="col-xs-12" style="  text-align: center;">
                                <img id="tableLoader" class="img-responsive" src="<%= Url.Content("~/Content/img/ajax-loader.gif")%>" alt="loading" style=" display: none; margin: 0 auto;">
                            </div>
                              <div class=" col-md-12 col-sm-12  col-xs-12 no-padding mar-top-20" id='implementationsTable'>
</div>
                            </div>
                    </div>
                    </div>
                    </section>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="ScriptsHolder" runat="server">

    <script type="text/javascript">

        $(document).ready(function() {

            var currentLink = window.location.hash;

            if (currentLink) {
                var currentLinkMonth;
                var currentLinkYear;
                var items = currentLink.split(' ');
                var count = items.length;
                if (count > 1) {
                    currentLinkMonth = items[0];
                    currentLinkYear = items[1];
                } else {    //if
                    items = currentLink.split('%20');
                    count = items.length;
                    if (count > 1) {
                        currentLinkMonth = items[0];
                        currentLinkYear = items[1];
                    }   //if
                }   //else
                currentLinkMonth = currentLinkMonth.replace('#', '');
                var url = '<%= Url.Content("~/Ajax/MonthMasterDetailAjax") %>';
                $('#yearsId').val(currentLinkYear);
                $.ajax({
                    method: "POST",
                    url: url,
                    data: { year: currentLinkYear, languageName: "<%= Model.PageToGenerate.Language.language_name %>" },
                    success: function(response) {
                        fillMonthsCombo("monthSelectId", response);
                        $('#monthsLoader').hide();
                        $('#monthsSelectId').show();
                    },
                    complete: function(response) {
                        $('#monthSelectId option:contains("' + currentLinkMonth + '")').attr("selected", "selected");
                        $('#monthSelectId').change();
                    }
                });
            }
        });

        $("#yearsId").change(function() {
            clearTablesData();
            monthComboAjax($(this).val());
        });
        $("#monthSelectId").change(function() {
            clearTablesData();
            fillImplementationsTable($(this).val());
            // fillEngineTableWIX('<%= Url.Content("~/Ajax/ImplementationsMasterDetailAjax") %>', '<%= Model.PageToGenerate.Language.language_name %>', $(this).val());
        });

        function fillImplementationsTable(month) {
            if (!month) {
                return;
            }   //if
            $('#tableLoader').show();
            var url = '<%= Url.Content("~/Ajax/ImplementationsMasterDetailAjax") %>';

            $.ajax({
                method: "POST",
                url: url,
                data: { year: $('#yearsId').val(), month: month, languageName: "<%= Model.PageToGenerate.Language.language_name %>", languageId: "<%= Model.PageToGenerate.Language.language_id %>" }
            })
                .done(function(response) {
                    $('#tableLoader').hide();
                    $('#implementationsTable').html(response);
                })
                .fail(function(response) {
                    $('#tableLoader').hide();
                });
        }

        function clearTablesData() {
            $('#implementationsTable').html('');
        }
        function monthComboAjax(year) {
            if (!year) {
                return;
            }   //if
            $('#monthsSelectId').hide();
            $('#monthsLoader').show();
            var url = '<%= Url.Content("~/Ajax/MonthMasterDetailAjax") %>';

            $.ajax({
                method: "POST",
                url: url,
                data: { year: year, languageName: "<%= Model.PageToGenerate.Language.language_name %>" }
            })
                .done(function(response) {
                    fillMonthsCombo("monthSelectId", response);
                    $('#monthsLoader').hide();
                    $('#monthsSelectId').show();
                })
                .fail(function(response) {
                    $('#monthsLoader').hide();
                    $('#monthsSelectId').show();
                });
        }
        function fillMonthsCombo(id, colonElements) {
            if ($('#' + id).length > 0) {
                var optionsValues = "";
                if (colonElements != null) {
                    var items = colonElements.split(";");
                    var count = items.length;
                    for (var i = 0; i < count; i++) {
                        var options = items[i].split("|");
                        if (options[0] != "") {
                            optionsValues += '<option value="' + options[1] + '">' + options[0] + '</option>';
                        }   //if
                    } //for
                    $('#' + id).html(optionsValues);
                }   //if
            }   //if
        }

       
    </script>

</asp:Content>
